package com.ljwm.dubbo.demo.consumer;

import com.ljwm.dubbo.demo.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.IntStream;

/**
 * Created by yuzhou on 2017/8/3.
 */
public class DemoAction {

  private static final Logger _log = LoggerFactory.getLogger(DemoAction.class);

  private DemoService demoService;

  public void setDemoService(DemoService demoService) {
    this.demoService = demoService;
  }

  public void start() {
    _log.info("Starting demo action ...");

    IntStream.range(Integer.MIN_VALUE, Integer.MAX_VALUE).forEach(i -> {
      _log.info("{} Call hello from service", i);
      String hello = demoService.sayHello("Client " + i);
      _log.info("Response from server: {}", hello);
      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        _log.error("Interrupted in sleep", e);
      }
    });

    _log.info("Over");
  }
}
